package com.hddf.project.service;

import org.hibernate.Session;
import org.kommii.mysql_conn_pool.SessionProvider;

import com.hddf.project.dao.RunTimeDao;
import com.hddf.project.impl.RunTimeDaoImpl;
import com.hddf.project.util.O;

public class RunTimeService {

	private static RunTimeDao rtd = null;
	private static RunTimeService rts = null;

	static {
		if (null == rtd) {
			rtd = new RunTimeDaoImpl();
		}
		if (null == rts) {
			rts = new RunTimeService();
		}
	}

	public static RunTimeService getInService() {
		return rts;
	}

	/**
	 * 
	 * @param time
	 * @throws Exception
	 */
	public void updateHistory() throws Exception {
		Session s = null;
		try {
			String time = O.getTimestamp2();
			int year = Integer.valueOf(time.substring(0, 4));
			String month = time.substring(4, 6);
			time = year - 1 + "-" + month;
			s = SessionProvider.getSession();
			rtd.updateHistory(time, s);
			SessionProvider.commitSession(s);
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}
}